windows permissions fix
authorJoey Hess <joeyh@joeyh.name>
Tue, 7 Jan 2025 20:37:39 +0000 (16:37 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 7 Jan 2025 20:37:39 +0000 (16:37 -0400)
Windows: Fix permission denied error when dropping files that have the
readonly attribute set.

Files coming from a special remote may have had write permission removed
from them. The directory special remote does that. And there are
probably others. So rather than fixing it on the special remote side,
made moveAnnex, on Windows, add back the write bit. This apparently
removes the readonly attribute. See Remote.Directory.removeDirGeneric
which already did the same on windows to allow removing files from the
directory special remote.

The reason that cleanObjectLoc also calls allowWrite is to handle
situations where files have already gotten into git-annex repositories on
Windows with the write bit set. Eg, an older git-annex put them there.
Or perhaps the git-annex repository was populated on some other OS.

Annex/Content.hs
CHANGELOG
doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__.mdwn
doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/comment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment [new file with mode: 0644]
doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__.mdwn
doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__/comment_5_9a591141f1105490f359b58a3b29cd91._comment [new file with mode: 0644]

index 93d111140f50cbbbca0bafffca37669b8d7ccc28..63746298d9d281f2967934e3996bbadf1f026ffd 100644 (file)
@@ -512,6 +512,12 @@ withTmp key action = do
 moveAnnex :: Key -> AssociatedFile -> RawFilePath -> Annex Bool
 moveAnnex key af src = ifM (checkSecureHashes' key)
        ( do
+#ifdef mingw32_HOST_OS
+               {- Windows prevents deletion of files that are not
+                - writable, and the file could have such a mode.
+                - So avoid problems with deleting the file, now or later. -}
+               void $ liftIO $ tryIO $ allowWrite src
+#endif
                withObjectLoc key storeobject
                return True
        , return False
@@ -733,7 +739,11 @@ cleanObjectLoc key cleaner = do
         -}
        whenM hasThawHook $
                void $ tryIO $ thawContent file
-               
+#ifdef mingw32_HOST_OS
+       {- Windows prevents deletion of files that are not writable. -}
+       void $ liftIO $ tryIO $ allowWrite file
+#endif
+
        cleaner
        cleanObjectDirs file
 
index 70c26b518b4a561dd129f074b68d49e4668cd420..b412a2060282da86fea651ad20d9723da664afa8 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,8 @@ git-annex (10.20250103) UNRELEASED; urgency=medium
   * Allow enableremote of an existing webdav special remote that has
     read-only access.
   * git-remote-annex: Use enableremote rather than initremote.
+  * Windows: Fix permission denied error when dropping files that
+    have the readonly attribute set.
 
  -- Joey Hess <id@joeyh.name>  Fri, 03 Jan 2025 14:30:38 -0400
 
index 87a0c37e612c4851c26a4450dd7ddc3f0c486745..939c979a3370b000728c958212a84392df49940b 100644 (file)
@@ -131,3 +131,5 @@ This observation comes from an effort to implement a git-remote-helper that uses
 
 [[!tag projects/datalad]]
 [[!tag projects/INM7]]
+
+> I think this is [[fixed|done]] now.. --[[Joey]]
diff --git a/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/comment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment b/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/comment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment
new file mode 100644 (file)
index 0000000..08aa9e4
--- /dev/null
@@ -0,0 +1,12 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 4"""
+ date="2025-01-07T20:33:22Z"
+ content="""
+I see that the directory special remote, on windows, adds back the write
+permission on files before removing them. That was done way back in
+[[!commit 38022f4f493588505896635703c34afa6c2e2406]].
+
+I've applied the same fix now to the annex objects side, so this should be
+fixed.
+"""]]
index 10a823cca63d5c7897d9b70df7fa646bd5199613..8e38f1c17d05ba3dc73563ff75f60c053f45bb94 100644 (file)
@@ -498,3 +498,5 @@ say I'm a believer. :)
 [[!meta author=jkniiv]]
 
 [[!tag projects/INM7]]
+
+> I think this is [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__/comment_5_9a591141f1105490f359b58a3b29cd91._comment b/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__/comment_5_9a591141f1105490f359b58a3b29cd91._comment
new file mode 100644 (file)
index 0000000..0b3b531
--- /dev/null
@@ -0,0 +1,12 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 5"""
+ date="2025-01-07T20:31:07Z"
+ content="""
+I see that the directory special remote, on windows, adds back the write
+permission on files before removing them. That was done way back in
+[[!commit 38022f4f493588505896635703c34afa6c2e2406]].
+
+I've applied the same fix now to the annex objects side, so this should be
+fixed.
+"""]]